package com.wechat.page.contact;

import org.controlsfx.glyphfont.FontAwesome;

import com.swak.fx.support.AbstractPage;
import com.swak.fx.support.FXMLView;
import com.swak.fx.support.ui.UI;
import com.swak.fx.support.ui.UIAction;
import com.swak.fx.support.ui.UIIcon;
import com.swak.fx.support.ui.UISearchBar;
import com.swak.fx.support.ui.UIStackPane;
import com.wechat.page.contact.find.FindPage;
import com.wechat.page.contact.list.ListPage;

import javafx.fxml.FXML;
import javafx.geometry.Insets;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;

/**
 * ContactListPage.
 * 
 * @author 618lf
 */
@FXMLView(title = "联系人列表", value = "ContactListPage.fxml", css = "ContactListPage.css")
public class ContactListPage extends AbstractPage {

	@FXML
	private GridPane searchPane;
	@FXML
	private UIStackPane contentPane;

	// ========================
	// 搜索
	// ========================
	private UISearchBar searchInput;
	private UIAction addGroupBtn;

	// ========================
	// 列表
	// ========================
	private ListPage listPage;

	public ContactListPage() {
		this.listPage = this.NewPage(ListPage.class);
	}

	@Override
	public void initializeParts() {
		super.initializeParts();
		this.initializeSearchParts();

		this.contentPane.setPrefHeight(0);
		this.contentPane.getChildren().add(this.listPage.getRoot());
		GridPane.setVgrow(contentPane, Priority.ALWAYS);
		GridPane.setHgrow(contentPane, Priority.ALWAYS);
	}

	private void initializeSearchParts() {
		this.searchInput = new UISearchBar();
		this.addGroupBtn = new UIAction();

		this.searchInput.clear();
		this.searchInput.getStyleClass().add("search");
		this.addGroupBtn.textNodeProperty().set(new UIIcon(FontAwesome.Glyph.PLUS).Tip("添加好友"));
		this.addGroupBtn.getStyleClass().add("add-group-btn");
		this.searchPane.add(searchInput, 0, 0);
		this.searchPane.add(addGroupBtn, 1, 0);
		GridPane.setHgrow(searchInput, Priority.ALWAYS);
		GridPane.setHgrow(searchPane, Priority.ALWAYS);

		GridPane.setMargin(searchInput, new Insets(0, 10, 0, 0));
	}

	@Override
	public void setupEventHandlers() {
		super.setupEventHandlers();
		this.registerUIEvent(searchPane, UI.Events.Window_Drag);
		this.addGroupBtn.addEventHandler(MouseEvent.MOUSE_CLICKED, (e) -> {
			FindPage findPage = FindPage.New();
			findPage.show();
		});
	}

	@Override
	public void setupBindings() {
		super.setupBindings();
	}

	@Override
	public void setupValueChangedListeners() {
		super.setupValueChangedListeners();
	}
}
